const db = require('../utils/db');
const express = require('express');
const router = express.Router();
const opera = require('../utils/dbOperation')
const result = require('../utils/response')
const uid = require('../utils/getUid')

router.post('/superList',(req,res) =>{
  const data = req.body;
  const flag = data.flag;
  delete data.flag;

  opera.select("pro_project_database_rel",data,(results) => {
    const dbIds = [];
    for (const item of results) {
      dbIds.push(item.database_id)
    }

    db.query(`select * from pro_table where find_in_set(database_id,?)`,[`${dbIds}`],(resultss) => {
      if (flag == 'yes') {
        opera.findOne('pro_project',{id:data.project_id},(back) => {
          const ign = eval(back.ignore_tables || '');
          const value = resultss.filter((val) => !ign || ign.indexOf(`${val.id}`) < 0);
          res.send(result.success(value));
        })
      } else {
        res.send(result.success(resultss));
      }
    })
  })
})

router.post('/list',(req,res) =>{
  const data = req.body;
  opera.select("pro_table",data,(results) => {
    res.send(result.success(results));
  },null,'create_time')
})


module.exports = router;
